package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.History;
import com.whxy02.tolearn.app.dao.HistoryDao;
import com.whxy02.tolearn.app.service.HistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HistoryServiceImpl implements HistoryService {
    private QueryWrapper<History> wrapper=new QueryWrapper<>();
    @Resource
    HistoryDao historyDao;

    @Override
    public List<History> getAll() throws Exception {
        return historyDao.selectList(null);
    }

    @Override
    public History getById(Integer id) throws Exception {
        return historyDao.selectById(id);
    }

    @Override
    public int save(History history) throws Exception {
        return historyDao.insert(history);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return historyDao.deleteById(id);
    }

    @Override
    public int change(History history) throws Exception {
        return historyDao.updateById(history);
    }

    @Override
    public List<History> getByUserId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("user_id",id).orderByDesc("create_time");
        return historyDao.selectList(wrapper);
    }
}
